<?php

declare(strict_types=1);

namespace App\Goods\Model;

use Hyperf\Database\Model\Relations\BelongsToMany;
use Mine\MineModel;

/**
 * @property int $goods_id 商品ID
 * @property int $goods_type 商品类型(10实物商品)
 * @property string $goods_name 商品名称
 * @property string $goods_no 商品编码
 * @property int $video_id 主图视频ID
 * @property int $video_cover_id 主图视频ID
 * @property string $selling_point 商品卖点
 * @property int $spec_type 商品规格(10单规格 20多规格)
 * @property string $goods_price_min 商品价格(最低)
 * @property string $goods_price_max 商品价格(最高)
 * @property string $line_price_min 划线价格(最低)
 * @property string $line_price_max 划线价格(最高)
 * @property int $stock_total 库存总量(包含所有sku)
 * @property int $deduct_stock_type 库存计算方式(10下单减库存 20付款减库存)
 * @property int $is_restrict 是否开启限购(0未开启 1已开启)
 * @property int $restrict_total 总限购数量(0为不限制)
 * @property int $restrict_single 每单限购数量(0为不限制)
 * @property string $content 商品详情
 * @property int $sales_initial 初始销量
 * @property int $sales_actual 实际销量
 * @property int $delivery_id 配送模板ID
 * @property int $is_points_gift 是否开启积分赠送(1开启 0关闭)
 * @property int $is_points_discount 是否允许使用积分抵扣(1允许 0不允许)
 * @property int $is_alone_points_discount 积分抵扣设置(0默认抵扣 1单独设置抵扣)
 * @property string $points_discount_config 单独设置积分抵扣的配置
 * @property int $is_enable_grade 是否开启会员折扣(1开启 0关闭)
 * @property int $is_alone_grade 会员折扣设置(0默认等级折扣 1单独设置折扣)
 * @property string $alone_grade_equity 单独设置折扣的配置
 * @property int $is_ind_delivery_type 是否单独设置配送方式(0关闭 1开启)
 * @property string $delivery_type 商品配送方式(仅单独设置时有效)
 * @property int $status 商品状态(10上架 20下架)
 * @property int $sort 排序(数字越小越靠前)
 * @property int $is_delete 是否删除
 * @property int $store_id 商城ID
 * @property int $create_time 创建时间
 * @property int $update_time 更新时间
 */
class GoodsInfo extends MineModel
{
    protected string $primaryKey = 'id';
    protected ?string $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'goods_info';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['goods_id', 'goods_type', 'goods_name', 'goods_no', 'video_id', 'video_cover_id', 'selling_point', 'spec_type', 'goods_price_min', 'goods_price_max', 'line_price_min', 'line_price_max', 'stock_total', 'deduct_stock_type', 'is_restrict', 'restrict_total', 'restrict_single', 'content', 'sales_initial', 'sales_actual', 'delivery_id', 'is_points_gift', 'is_points_discount', 'is_alone_points_discount', 'points_discount_config', 'is_enable_grade', 'is_alone_grade', 'alone_grade_equity', 'is_ind_delivery_type',  'status', 'sort', 'is_delete', 'store_id', 'create_time', 'update_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['goods_id' => 'integer', 'goods_type' => 'integer', 'video_id' => 'integer', 'video_cover_id' => 'integer', 'spec_type' => 'integer', 'goods_price_min' => 'decimal:2', 'goods_price_max' => 'decimal:2', 'line_price_min' => 'decimal:2', 'line_price_max' => 'decimal:2', 'stock_total' => 'integer', 'deduct_stock_type' => 'integer', 'is_restrict' => 'integer', 'restrict_total' => 'integer', 'restrict_single' => 'integer', 'sales_initial' => 'integer', 'sales_actual' => 'integer', 'delivery_id' => 'integer', 'is_points_gift' => 'integer', 'is_points_discount' => 'integer', 'is_alone_points_discount' => 'integer', 'is_enable_grade' => 'integer', 'is_alone_grade' => 'integer', 'is_ind_delivery_type' => 'integer', 'status' => 'integer', 'sort' => 'integer', 'is_delete' => 'integer', 'store_id' => 'integer', 'create_time' => 'integer', 'update_time' => 'integer'];

    public function category(): BelongsToMany
    {
        return $this->belongsToMany(GoodsCategory::class, 'goods_id', 'user_id', 'category_id');
    }
}
